package icu.shaoyayu.security.dome1.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.xml.ws.soap.Addressing;

/**
 * @author shaoyayu
 * @Version 1.0.0
 * @readme ：
 */
@Slf4j
@Service
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private PasswordEncoder pw;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        log.info("user information authentication......");
        if (!"admin".equals(username)){
            throw new UsernameNotFoundException("用户名不存在！！！");
        }
        String password = pw.encode("123");

        return new User(username,password, AuthorityUtils.commaSeparatedStringToAuthorityList(
                "admin,normal"
        ));
    }
}
